package project.parser.ast.exps;

import project.environments.DynamicEnv;
import project.environments.StaticEnv;
import project.environments.Value;
import project.parser.ast.types.Type;

public final class Ident implements Exp {
	private final String name;

	public Ident(String name) {
		if (name == null)
			throw new IllegalArgumentException("Identifier name cannot be null");
		this.name = name;
	}

	public String getName() {
		return name;
	}

	@Override
	public String toString() {
		return name;
	}

	@Override
	public int hashCode() {
		return name.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof Ident))
			return false;
		return name.equals(((Ident)obj).name);
	}

	@Override
	public Type typecheck(StaticEnv senv) {
		return senv.lookup(this);
	}

	@Override
	public Value evaluate(DynamicEnv denv) {
		return denv.lookup(this);
	}

}
